import axios from 'axios';
import nProgress from 'nprogress';
import 'nprogress/nprogress.css';
import {
    userTempId
} from '@/utils/temp_token';
import store from '@/store';

let instance = axios.create({
    baseURL: '/api',
    timeout: 5000
});

instance.interceptors.request.use((config) => {
    nProgress.start();

    //设置用户临时身份
    config.headers.userTempId = userTempId();

    //设置用户的token
    if (store.getters.token)
        config.headers.token = store.getters.token;

    return config;
});

instance.interceptors.response.use((res) => {
    nProgress.done();
    return res.data;
}, (err) => {
    return Promise.reject(err);
})



export default instance;